package treeedit;

import java.awt.Color;

import javax.swing.JLabel;

public class Messanger 
{
	static private Messanger instance = null;
	static private  JLabel label;
	
	protected Messanger() 
	{
		
	}
	
	static public void setLabel(JLabel l)
	{
		label = l;
	}
	
	static public Messanger getInstance ()
	{
		if(instance == null) 
			instance = new Messanger();
			
		return instance;
	}
	
	static public Messanger getInstance (JLabel l)
	{
		label = l;
		return getInstance();
	}
	
	
	public void setMessage ( String str )
	{
		label.setForeground(Color.black);
		label.setText(str);
	}
	
	public void setMessage ( String str, int timeout)
	{
		setMessage(str);
		new Worker(timeout).start();
	}
	
	public void setError ( String str, int timeout)
	{
		label.setForeground(Color.red);
		label.setText(str);
		new Worker(timeout).start();
	}
	
	private class Worker extends Thread
	{
		private int timeout;
		
		public Worker (int timeout )
		{
			super();
			this.timeout = timeout;
		}
		
		public void run ( )
		{
			try {
				Thread.sleep(timeout);
			} catch (InterruptedException e) {}
			
			label.setText("Idle");
			
		}
	}
}
